package com.crois.barrier.admin.configuration;

import com.alibaba.cloud.nacos.NacosConfigProperties;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Properties;

/**
 * @author Hou Ze Yu
 * @description   nacos 配置
 * @date 2020/7/13
 */
@Configuration
public class NacosConfigConfiguration {

    @Autowired
    private NacosConfigProperties nacosProperties;

    /***
     * nacos config
     * @return
     * @throws NacosException
     */
    @Bean
    public ConfigService barrierSyncNacosConfigService() throws NacosException {
        Properties properties=new Properties();
        properties.put(PropertyKeyConst.SERVER_ADDR, nacosProperties.getServerAddr());
        properties.put(PropertyKeyConst.NAMESPACE, nacosProperties.getNamespace());
        return NacosFactory.createConfigService(properties);
    }


}
